package com.lengyu.vxminiprogram.common;

import com.alibaba.fastjson.JSONObject;
import com.lengyu.vxminiprogram.security.rest.dto.JwtUser;
import org.springframework.security.core.context.SecurityContextHolder;

public class AuthUtil {
    public static JwtUser getCurrentJwtUser(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String jwtUserStr = String.valueOf(principal);
        // 获得loadUserByUsername()方法的结果
        JwtUser jwtUser = JSONObject.toJavaObject(JSONObject.parseObject(jwtUserStr),JwtUser.class);
        return jwtUser;
    }
}
